package com.senior.sendmessage.config;

import cn.hutool.core.util.ObjectUtil;
import com.senior.sendmessage.entity.CityListDTO;
import com.senior.sendmessage.xxl.WeatherScheduleJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Baijl
 * @version 0.0.1
 * @date 2021-12-12 11:58
 * @description 程序启动后加载的方法
 */
@Slf4j
@Component
public class RunnerConfig implements ApplicationRunner {
    private WeatherScheduleJob weatherScheduleJob;

    @Autowired
    public void setWeatherScheduleTask(final WeatherScheduleJob weatherScheduleJob) {
        this.weatherScheduleJob = weatherScheduleJob;
    }

    @Override
    public void run(final ApplicationArguments args) {
        weatherScheduleJob.setCityList();
        log.info("启动时-城市列表查询完成！");
        final List<CityListDTO.ResultDTO> result = weatherScheduleJob.getCityList().getResult();
        if (ObjectUtil.isNotEmpty(result)) {
            log.info("缓存列表；缓存完成，共{}条", result.size());
        } else {
            log.info("查询缓存超过上限！");
        }
    }
}
